1
|
|
|
/* |
2
|
|
|
* Copyright (C) 2021 Joe Nilson <[email protected]> |
3
|
|
|
* |
4
|
|
|
* This program is free software: you can redistribute it and/or modify |
5
|
|
|
* it under the terms of the GNU Lesser General Public License as |
6
|
|
|
* published by the Free Software Foundation, either version 3 of the |
7
|
|
|
* License, or (at your option) any later version. |
8
|
|
|
* |
9
|
|
|
* This program is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU Lesser General Public License for more details. |
13
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
14
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param {string} tipoComprobante |
19
|
|
|
* @returns {Promise<*>} |
20
|
|
|
*/ |
21
|
|
|
async function verificarCorrelativoNCF(tipoComprobante, tipoOperacion) |
22
|
|
|
{ |
23
|
|
|
let ArrayTipoNCFCompras = ['11','12','16','17']; |
24
|
|
|
if (tipoOperacion === 'Compras' && !ArrayTipoNCFCompras.includes($("#doc_codsubtipodoc").val())) { |
25
|
|
|
return true; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
return $.ajax({ |
29
|
|
|
url: 'ListNCFRango', |
30
|
|
|
async: true, |
31
|
|
|
data: {'action': 'busca_correlativo', 'tipocomprobante': tipoComprobante}, |
32
|
|
|
type: 'POST', |
33
|
|
|
datatype: 'json', |
34
|
|
|
success: function (response) { |
35
|
|
|
let data = JSON.parse(response); |
36
|
|
|
if ( data.existe === false ) { |
37
|
|
|
executeModal( |
38
|
|
|
'verificaNCF', |
39
|
|
|
'No hay Correlativo de NCF Disponible', |
40
|
|
|
'No hay correlativos disponibles para el Tipo de NCF ' + |
41
|
|
|
tipoComprobante + ' <br/>Por favor revise su maestro de NCFs', |
42
|
|
|
'warning' |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
}, |
46
|
|
|
failure: function (response) { |
|
|
|
|
47
|
|
|
alert('Ha ocurrido algún tipo de falla ' + status); |
|
|
|
|
48
|
|
|
}, |
49
|
|
|
error: function (xhr, status) { |
50
|
|
|
alert('Ha ocurrido algún tipo de error ' + status); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
}); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* logConsole in Debug mode |
57
|
|
|
* @param value |
58
|
|
|
* @param description |
59
|
|
|
*/ |
60
|
|
|
function logConsole(value, description ='data') |
61
|
|
|
{ |
62
|
|
|
if ($(".debugbar") !== undefined) { |
63
|
|
|
console.log(description, value); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/******** |
68
|
|
|
* Util Functions |
69
|
|
|
*/ |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* |
73
|
|
|
* @param {object} btn |
74
|
|
|
* @param {string} text |
75
|
|
|
*/ |
76
|
|
|
function setLoadingButton(btn, text) |
77
|
|
|
{ |
78
|
|
|
$(btn).prop("disabled", true); |
79
|
|
|
$(btn).html( |
80
|
|
|
'<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>' + text |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
function saveBussinessDocument(btn) |
86
|
|
|
{ |
87
|
|
|
//Set the save button as loading |
88
|
|
|
setLoadingButton(btn,'Guardando...'); |
89
|
|
|
|
90
|
|
|
var data = {}; |
91
|
|
|
$.each($("#" + businessDocViewFormName).serializeArray(), function (key, value) { |
|
|
|
|
92
|
|
|
data[value.name] = value.value; |
93
|
|
|
}); |
94
|
|
|
data['ncftipopago'] = $('form #ncftipopago').val(); |
95
|
|
|
data['ncftipomovimiento'] = $('form #ncftipomovimiento').val(); |
96
|
|
|
data.action = "save-document"; |
97
|
|
|
data.lines = getGridData(); |
98
|
|
|
|
99
|
|
|
$.ajax({ |
100
|
|
|
type: "POST", |
101
|
|
|
url: businessDocViewUrl, |
|
|
|
|
102
|
|
|
dataType: "text", |
103
|
|
|
data: data, |
104
|
|
|
success: function (results) { |
105
|
|
|
if (results.substring(0, 3) === "OK:") { |
106
|
|
|
$("#" + businessDocViewFormName + " :input[name=\"action\"]").val('save-ok'); |
|
|
|
|
107
|
|
|
$("#" + businessDocViewFormName).attr('action', results.substring(3)).submit(); |
108
|
|
|
} else { |
109
|
|
|
alert(results); |
|
|
|
|
110
|
|
|
$("#" + businessDocViewFormName + " :input[name=\"multireqtoken\"]").val(randomString(20)); |
111
|
|
|
} |
112
|
|
|
}, |
113
|
|
|
error: function (msg) { |
114
|
|
|
alert(msg.status + " " + msg.responseText); |
|
|
|
|
115
|
|
|
} |
116
|
|
|
}); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
function isBusinessDocumentPage() |
120
|
|
|
{ |
121
|
|
|
let businessDocument = ''; |
122
|
|
|
if ($('#formEditFacturaProveedor').length > 0) { |
123
|
|
|
businessDocument = 'Compra'; |
124
|
|
|
} else if ($('#formEditFacturaCliente').length > 0) { |
125
|
|
|
businessDocument = 'Venta'; |
126
|
|
|
} |
127
|
|
|
return businessDocument; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
$(document).ready(function () { |
132
|
|
|
let tipoOperacion = isBusinessDocumentPage(); |
133
|
|
|
let varCodSubtipoDoc = $("#doc_codsubtipodoc"); |
134
|
|
|
if (varCodSubtipoDoc.val() !== '' && tipoOperacion !== '') { |
135
|
|
|
verificarCorrelativoNCF($("#doc_codsubtipodoc").val(), tipoOperacion); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
varCodSubtipoDoc.change(function () { |
139
|
|
|
logConsole(varCodSubtipoDoc.val(),"#doc_codsubtipodoc val"); |
140
|
|
|
if (tipoOperacion !== '') { |
141
|
|
|
verificarCorrelativoNCF(varCodSubtipoDoc.val(), tipoOperacion); |
142
|
|
|
} |
143
|
|
|
}); |
144
|
|
|
|
145
|
|
|
// $("#doc_codsubtipodoc").change(function() { |
146
|
|
|
// logConsole($("#doc_codsubtipodoc").val(),"#doc_codsubtipodoc val"); |
147
|
|
|
// if(ArrayTipoNCFCompras.includes($("#doc_codsubtipodoc").val())) { |
148
|
|
|
// verificarCorrelativoNCF($("#doc_codsubtipodoc").val()); |
149
|
|
|
// } |
150
|
|
|
// }); |
151
|
|
|
}); |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.